#include "dlist.h"
#include <stdio.h>
#include <stdlib.h>

int dlist_add(NODE** head,DATA data)
{
	NODE* pnew = (NODE*)malloc(sizeof(NODE));
	if(!pnew)	
	{
		puts("内存插入失败!");
		return -1;
	}
	pnew -> data = data;
	pnew -> prev = NULL;
	pnew -> next = NULL;
	if(!(*head))
	{
		*head = pnew;
		return 0;
	}
	NODE* p = *head;
	while(p -> next)
	{
		p = p -> next;
	}
	p -> next = pnew;
	pnew -> prev = p;
	return 0;
}

void dlist_print(const NODE* head)
{
	const NODE* p = head;
	if(!p)
		return ;

	printf("线路:%d,起始站:%s,终点站:%s,里程数:%d\n",p -> data.route,p -> data.start,p -> data.end,p -> data.mileage);
	dlist_print(p -> next);
}

void dlist_free(NODE** head)
{
	NODE *p = *head, *q = NULL;
   
        while(p)
        {
                q = p;
                p = p -> next;
                free(q);
        }
        *head = NULL;
}
